package org.hamcrest.collection;

import java.util.Iterator;
import org.hamcrest.Factory;
import org.hamcrest.FeatureMatcher;
import org.hamcrest.Matcher;
import org.hamcrest.core.IsEqual;

/* loaded from: classes2.dex */
public class IsIterableWithSize<E> extends FeatureMatcher<Iterable<E>, Integer> {
    @Override // org.hamcrest.FeatureMatcher
    protected /* bridge */ /* synthetic */ Integer featureValueOf(Object obj) {
        return featureValueOf((Iterable) ((Iterable) obj));
    }

    public IsIterableWithSize(Matcher<? super Integer> matcher) {
        super(matcher, "an iterable with size", "iterable size");
    }

    protected Integer featureValueOf(Iterable<E> iterable) {
        Iterator<E> it = iterable.iterator();
        int i = 0;
        while (it.hasNext()) {
            i++;
            it.next();
        }
        return Integer.valueOf(i);
    }

    @Factory
    public static <E> Matcher<Iterable<E>> iterableWithSize(Matcher<? super Integer> matcher) {
        return new IsIterableWithSize(matcher);
    }

    @Factory
    public static <E> Matcher<Iterable<E>> iterableWithSize(int i) {
        return iterableWithSize(IsEqual.equalTo(Integer.valueOf(i)));
    }
}
